package com.llmcu.source.javase.thread.producerandconsumer;

import java.util.concurrent.TimeUnit;

public class Producer implements Runnable {
    private final Basket basket;

    public Producer(Basket basket) {
        this.basket = basket;
    }

    @Override
    public void run(){

        while (true) {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
            // 生产一个馒头
            try {
                basket.push(new Mantou());
            } catch (InterruptedException e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
        }
    }
}


